package appconfig

import (
	"errors"
	"fmt"
	"github.com/spf13/viper"
)

type AppConfig struct {
	MysqlApp MysqlApp `json:"mysql_app"`
	RedisApp RedisApp `json:"redis_app"`
}
type MysqlApp struct {
	Hort     string `json:"hort"`
	Username string `json:"username"`
	Password string `json:"password"`
	Part     int    `json:"part"`
	Data     string `json:"data"`
}
type RedisApp struct {
	Addr     string `json:"addr"`
	Pass     int    `json:"pass"`
	Password string `json:"password"`
	DB       int    `json:"db"`
}

var AppCon AppConfig

func AppInit() {
	viper.SetConfigFile("../dev.yaml")
	err := viper.ReadInConfig()
	if err != nil {
		panic(errors.New("读取失败"))
	}
	err = viper.Unmarshal(&AppCon)
	fmt.Println("动态配置连接成功", AppCon)
	if err != nil {
		fmt.Println("解析失败", err)
		return
	}
	fmt.Println("动态配置连接成功", AppCon)

}
